<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.bolinfest.editor.PMF" %>
<%@ page import="com.bolinfest.editor.TokenStore" %>
<%@ page import="com.bolinfest.editor.UserPreferences" %>
<%@ page import="com.bolinfest.editor.util.JsonUtil" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="javax.jdo.JDOObjectNotFoundException" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%
  UserService userService = UserServiceFactory.getUserService();
  User user = userService.getCurrentUser();
  UserPreferences prefs = UserPreferences.getPrefsForUser(
      user, PMF.get().getPersistenceManager());
%>
<!doctype html>
<html>
<head>
  <title>NJEdit</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <link rel="STYLESHEET" href="editor.css" type="text/css">
</head>
<body>

<% if (request.getRequestURL().toString().startsWith(
    "http://docbookeditor.appspot.com/")) { %>
<script src="docbookeditor.js"></script>
<% } else { %>
<script src="http://localhost:9810/compile?id=docbookeditor&mode=RAW"></script>
<% } %>

<script>
initEditor('<%= user.getEmail() %>',
           '<%= TokenStore.getToken(user) %>',
           '<%= userService.createLogoutURL("/") %>',
           <%= JsonUtil.serialialzeSet(prefs.getDocumentIds()) %>);
</script>

<jsp:include page="analytics.jsp" />

</body>
</html>
